package com.example.demo.service.Impl;

import com.example.demo.bean.Application;
import com.example.demo.bean.ApplicationExample;
import com.example.demo.dao.ApplicationMapper;
import com.example.demo.service.IApplicationService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class ApplicationServiceImpl implements IApplicationService {
@Resource
private ApplicationMapper applicationMapper;




    @Override
    public List<Application> query(Long id, String name) {
        ApplicationExample example = new ApplicationExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%" + name + "%");
        }
        if (!StringUtils.isEmpty(id)) {
            example.createCriteria().andIdEqualTo(id);
        }
        List<Application> list = applicationMapper.selectByExample(example);
        return list;

    }

    @Override
    public void saveOrUpdate(Application application) {
        if(application.getId()==null){
            application.setCreateTime(new Date().getTime());
            applicationMapper.insert(application);
        }else{
            applicationMapper.updateByPrimaryKey(application);
        }
    }

    @Override
    public void deleteById(long id) {
        applicationMapper.deleteByPrimaryKey(id);
    }
}


